﻿using AutoMapper;
using MediatR;
using SupplyChain.Domain.Entities;
using SupplyChain.Infrastructure.Interface;
using SupplyChain.Write.API.Application.Command.CustomerOrder;
using SupplyChain.Write.API.Application.Command.PurchaseOrder;

namespace SupplyChain.Write.API.Application.CommandHandler.CustomerOrder
{
    public class DelContractCategoryHandler : IRequestHandler<DelContractCategoryCommand, bool>
    {
        private readonly IBaseRepository<ContractCategory> repository;
        private readonly IMapper mapper;

        public DelContractCategoryHandler(IBaseRepository<ContractCategory> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        public async Task<bool> Handle(DelContractCategoryCommand request, CancellationToken cancellationToken)
        {
            if (request.Id <= 0) return await Task.FromResult(false);

            ContractCategory category = await repository.GetByPrimaryKeyAsync(request.Id);
            category.IsDel = !category.IsDel;
            return await Task.FromResult(await repository.UpdateAsync(category));
        }
    }
}
